package com.cqie.hospitalescort.controller;


import com.cqie.hospitalescort.model.Result;
import com.cqie.hospitalescort.utils.ResponseUtil;

import java.util.Arrays;

/**
 * 控制器基类
 */
public abstract class BaseController {

    /**
     * 返回成功数据
     */
    protected <T> Result<T> response(T data) {
        return ResponseUtil.getSuccessResult(data);
    }

    /**
     * 返回操作成功
     *
     * @return
     */
    protected <T> Result<T> response() {
        return ResponseUtil.getSuccessResult(null);
    }

    protected <T> Result<T> responseError(String msg) {
        return ResponseUtil.getErrorResult(msg);
    }

    /**
     * 返回值自定义错误消息
     *
     * @return
     */
    protected Result<Object> responseMsg(int errorCode, Object... args) {
        return new Result<>(errorCode, Arrays.toString(args));
    }
}
